home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / snoopdos_source / language.c < prev    next >
C/C++ Source or Header  |  1996-02-16  |  3KB  |  98 lines

  1. /*
  2.  *        LANGUAGE.C                                                    vi:ts=4
  3.  *
  4.  *      Copyright (c) Eddy Carroll, September 1994.
  5.  *
  6.  *        This module deals with localisation and sets up the string table
  7.  *        used by all other parts of SnoopDos.
  8.  */
  9.  
  10. #define CATCOMP_ARRAY
  11.  
  12. #define SNOOPDOS_CAT        "SnoopDos.catalog"
  13.  
  14. #include "system.h"
  15. #include "snoopdos.h"
  16.  
  17. struct LocaleBase    *LocaleBase;
  18. struct Catalog        *SnoopDosCat;
  19.  
  20. /*
  21.  *        InitTextTable()
  22.  *
  23.  *        Initialises the global text table from the default string array
  24.  *        (created for us by CatComp in SNOOPTEXT.H)
  25.  *
  26.  *        We build our own table because CatComp generates a "packed" array
  27.  *        which doesn't leave gaps for any strings we might have deleted
  28.  *        from the language file during development. Our own array allows
  29.  *        us to always directly obtain a string by saying MSG(MSG_FILEIO_GAD)
  30.  *        or something similar.
  31.  */
  32. void InitTextTable(void)
  33. {
  34.     int i;
  35.  
  36.     for (i = 0; CatCompArray[i].cca_ID != NUM_OF_MSGS; i++)
  37.         TextTable[CatCompArray[i].cca_ID] = CatCompArray[i].cca_Str;
  38. }
  39.  
  40. /*
  41.  *        InitLocale(catalogname)
  42.  *
  43.  *        Initialises the text table using the user's current Locale.
  44.  *        'name' is the name of the catalog to use; this can be an
  45.  *        absolute pathname to a different catalog if you like.
  46.  *
  47.  *        Note that you must have called InitTextTable() before calling
  48.  *        this. Note also that you should call CleanupLocale() before
  49.  *        exiting the program, even if the InitLocale() didn't work.
  50.  */        
  51. void InitLocale(char *langname)
  52. {
  53.     APTR oldwinptr = *TaskWindowPtr;
  54.     int i;
  55.  
  56.     /*
  57.      *        We disable window requesters when looking for our catalog
  58.      *        since otherwise, if ENV: hasn't been assigned, we get requesters
  59.      *        asking for ENV: to be inserted which is a bit annoying if you
  60.      *        run SnoopDos after booting with no startup-sequence.
  61.      */
  62.     LocaleBase      = (struct LocaleBase *)OpenLibrary("locale.library", 0);
  63.     if (!LocaleBase)
  64.         return;
  65.     
  66.     *TaskWindowPtr = (APTR)-1;
  67.     if (langname && *langname) {
  68.         SnoopDosCat = OpenCatalog(NULL, SNOOPDOS_CAT,
  69.                                         OC_BuiltInLanguage,    "english",
  70.                                         OC_Language,        langname,
  71.                                         TAG_DONE);
  72.     } else {
  73.         SnoopDosCat = OpenCatalog(NULL, SNOOPDOS_CAT,
  74.                                         OC_BuiltInLanguage,    "english",
  75.                                         TAG_DONE);
  76.     }
  77.     *TaskWindowPtr = oldwinptr;
  78.  
  79.     if (!SnoopDosCat) {
  80.         /* Use default language */
  81.         return;
  82.     }
  83.     
  84.     for (i = 0; i < NUM_OF_MSGS; i++)
  85.         TextTable[i] = GetCatalogStr(SnoopDosCat, i, TextTable[i]);
  86. }
  87.  
  88. /*
  89.  *        CleanupLocale()
  90.  *
  91.  *        Closes any resources opened by InitLocale()
  92.  */
  93. void CleanupLocale(void)
  94. {
  95.     if (SnoopDosCat)        CloseCatalog(SnoopDosCat),    SnoopDosCat = NULL;
  96.     if (LocaleBase)            CloseLibrary(LocaleBase),    LocaleBase    = NULL;
  97. }
  98.